layui.use('layer', function () {
    layer = layui.layer;
});

var iframeIndex;

/*添加*/
function add(title, url, w, h, full = false, reload = null, closeRefresh = false) {
    open_iframe(title, url, w, h, full, reload, closeRefresh);
}

/*删除*/
function del(obj, id) {
    layer.confirm('确认要删除吗？', function (index) {
        //异步删除数据
        $(obj).parents("tr").remove();
        layer.msg('已删除!', { icon: 1, time: 1000 });
    });
}

/*弹出层*/
function open_iframe(title, url, w, h, full = false, reload = null, closeRefresh = false) {
    if (title == null || title == '') {
        title = false;
    };
    if (url == null || url == '') {
        url = "404.html";
    };
    if (w == null || w == '') {
        w = 800;
    };
    if (h == null || h == '') {
        h = ($(window).height() - 50);
    };
    var isClose = false;
    iframeIndex = layer.open({
        type: 2,
        area: [w + 'px', h + 'px'],
        fix: false, //不固定
        maxmin: true,
        shadeClose: true,
        shade: 0.4,
        title: title,
        content: url,
        cancel: function (index) {
            if (!closeRefresh) {
                isClose = true;
            }
            layer.close(index);
        },
        end: function () {
            //判断fucntion
            if (typeof (reload) == "function" && !isClose) {
                //刷新父级列表
                reload();
            }
        }
    });
    if (full) {
        layer.full(iframeIndex);
    }
}